package com.example.meituan.activity.user;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.meituan.R;
import com.example.meituan.activity.man.ManageManActivity;
import com.example.meituan.activity.man.addShopActivity;
import com.example.meituan.activity.man.frament.ManageHomeFragment;
import com.example.meituan.activity.man.frament.ManageMyFragment;
import com.example.meituan.activity.user.farment.UserHomeFragment;
import com.example.meituan.activity.user.farment.UserMyFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

public class UserMainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_user_main);

        FragmentManager fragment_content=getSupportFragmentManager();

        //实现第一次跳转的界面
        FragmentTransaction transaction=fragment_content.beginTransaction();
        transaction.replace(R.id.user_main_frame,new UserHomeFragment());
        transaction.commit();
        BottomNavigationView bottomNavigationView=findViewById(R.id.user_bottom_menu);
        bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                FragmentTransaction f=fragment_content.beginTransaction();
                int id=item.getItemId();
                if(id==R.id.user_bottom_menu_home){
                    f.replace(R.id.user_main_frame,new UserHomeFragment());
                }
                if(id==R.id.user_bottom_menu_comment){
                    Intent intent=new Intent(UserMainActivity.this, MessageActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("ifUser", "user");
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
                if(id==R.id.user_bottom_menu_me){
                    f.replace(R.id.user_main_frame,new UserMyFragment());
                }
                if(id==R.id.user_bottom_menu_shop_car){
                    Intent intent=new Intent(UserMainActivity.this, ShopCarActivity.class);
                    startActivity(intent);
                }
                f.commit();
                return true;
            }
        });
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }
}